<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Warehousing
 * @package App\Models
 * @property Collection $products
 */
class Warehousing extends Model
{
    protected $table = 'warehousing';
    protected $fillable = [
        'customer_id', 'district', 'type', 'weight', 'price', 'transport', 'packing_code', 'piece', 'code', 'remark', 'product_count'
    ];

    protected static function boot()
    {
        static::addGlobalScope('orderBy', function (Builder $query){
            $query->orderByDesc('id');
        });
        parent::boot();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function products(){
        return $this->hasMany(WarehousingProduct::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function logs(){
        return $this->hasMany(WarehousingLog::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function customer(){
        return $this->belongsTo(Customer::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function files(){
        return $this->hasMany(WarehousingFile::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function tally(){
        return $this->hasMany(Tally::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function shelves(){
        return $this->hasMany(Shelves::class);
    }
}
